﻿using FrameworkCore.Models;
using FrameworkCore;
using Microsoft.AspNetCore.Mvc;
using AiBLSmartEdu.Module.SmartDictionaries.API.Services;
using FrameworkCore.Controllers;
using AiBLSmartEdu.Module.SmartDictionaries.API.DTOs;
using AiBLSmartEdu.Module.SmartDictonaries.API.DTOs;

namespace AiBLSmartEdu.Module.SmartDictionaries.API.Controllers;

/// <summary>
/// 智慧汉语词典
/// </summary>
public class SmartDictionariesController : BaseModuleController
{
    private readonly ChineseDictionaryServices _chineseDictionaryServices;

    public SmartDictionariesController(ChineseDictionaryServices chineseDictionaryServices)
    {
        _chineseDictionaryServices = chineseDictionaryServices;
    }

    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="filter">分页输入模型</param>
    /// <returns></returns>
    [HttpGet("Page")]
    public async Task<PageResult<ChineseDictionaryOutputModel>> Pagination([FromQuery] ChineseDictionaryPaginationFilter filter)
    {
        return await _chineseDictionaryServices.PageAsync(filter);
    }

    /// <summary>
    /// 简体/繁体转换
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPost("Convert/Chinese")]
    public async Task<Result<ConvertChineseOutputModel>> ConvertChineseAsync(ConvertChineseInputModel input)
    {
        return await Result<ConvertChineseOutputModel>.SucceedAsync(await _chineseDictionaryServices.ConvertChineseAsync(input));
    }

    /// <summary>
    /// 创建词汇
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Result> Create(ChineseDictionaryCreateInputModel input)
    {
        await _chineseDictionaryServices.CreateAsync(input);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 是否收藏
    /// </summary>
    /// <param name="id">唯一标识</param>
    /// <returns></returns>
    [HttpPut("Favorited/{id}")]
    public async Task<Result> IsFavorited(long id)
    {
        await _chineseDictionaryServices.IsFavoritedAsync(id);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 批量删除
    /// </summary>
    /// <returns></returns>
    [HttpDelete("{ids}")]
    public async Task<Result> BulkDeletes(string ids)
    {
        await _chineseDictionaryServices.DeleteAsync(ids);
        return await Result.SucceedAsync();
    }
}
